<form id="examPaper" class="layui-form " style="margin-top: 20px">
    <div class="layui-form-item">
        <label class="layui-form-label">试卷名</label>
        <div class="layui-input-block">
            <input id="epname" name="epname" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">简介要求</label>
        <div class="layui-input-block">
            <textarea id="remark" name="remark" class="layui-textarea"  ></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">参考小组</label>
        <div class="layui-input-block">
            <select id="group" name="grouid" class="layui-input" >

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
            <button class="layui-btn layui-btn-primary" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</form>
<script>
    layui.use(['index','form', 'config', 'admin','layer','table'], function () {
        var admin=layui.admin;
        var form=layui.form;
        var layer=layui.layer;
        var index=layui.index;
        var config=layui.config;
        var table=layui.table;

        let creator;
        index.getUser(function (user) {
             creator=user.id
        });
        let param={
            teacid:creator,
            access_token:config.getToken().access_token,
            page:1,
            limit:99999
        };
        $.ajax({
            type: 'post',
            url: config.base_server+'api-user/group/getGroupByTeacher',
            data: param,
            async: false, //同步
            dataType: 'json',
            xhrFields: {
                withCredentials: true //允许跨域带Cookie
            },
            success: function(res) {
                let data=res.data;
                for (let i = 0; i < data.length; i++) {
                    $("#group").append('<option value="'+data[i].grouid+'">'+data[i].gpname+'</option>')
                }
                form.render();
            }
        });

        //提交表单
        form.on("submit(saveBtn)",function (data) {
            data.field.creator=creator;
            console.log(data);
            admin.req("api-exam/examPaper/addPaper",JSON.stringify(data.field),function (res) {
                layer.msg(res.msg);
                if(res.code===0){
                    table.reload('exam-paper')
                }
            },"POST");
            return false;
        });
    });
</script>